package com.js.myapp.common.db;

// Created by JS on 2021/1/20.

import android.content.Context;

import com.js.myapp.application.MyApplication;
import com.js.myapp.gen.DaoSession;
import com.js.myapp.gen.TestEntityDao;

public final class DBService {
    private static final String TAG = "DBService";
    public static final String DB_NAME = "myapp_db";

    private static DBService sInstance;
    private static Context sAppContext;
    private DaoSession mDaoSession;

    /*表 dao 对象*/
    private TestEntityDao mTestEntityDao;

    private DBService() {}

    public static DBService getInstance(Context context) {
        if (sInstance == null) {
            sInstance = new DBService();
            if (sAppContext == null) sAppContext = context.getApplicationContext();
            sInstance.mDaoSession = MyApplication.getDaoSession(sAppContext);

            // 表 dao 对象创建
            sInstance.mTestEntityDao = sInstance.mDaoSession.getTestEntityDao();
        }
        return sInstance;
    }
}
